package mathsTrainingSystem;

import java.util.Scanner;
import mathsTrainingSystem.ErrorRecords.ErrorRecorder;

public class MathTraining {
	public static void modifyErrorRecorder(ErrorRecords errorRecords, int index, int a, int b, int c, int flag, int tag, int asw) {  
        ErrorRecorder recorder = errorRecords.getErrorRecorder(index);  
        if (recorder != null) {  
            recorder.a = a;
            recorder.b = b;
            recorder.c = c;
            recorder.flag = flag;
            recorder.tag = tag;
            recorder.asw = asw;
        }  
    } 
	
	public static void main(String[] args) {  
	    int command;  
	    Scanner scanner = new Scanner(System.in); // 只在这里创建一次Scanner对象 
	    ErrorRecords errorRecords = new ErrorRecords(30);   
	    while (true) {  
	        System.out.println("======欢迎使用小学数学训练软件！======");  
	        System.out.println("请选择：");  
	        System.out.println("[1]开始训练      [2]错题回顾");  
	        System.out.println("[3]退出程序"); 
	  
	        while (!scanner.hasNextInt()) {  
	            System.out.println("输入无效，请重新输入一个整数: ");  
	            scanner.next(); // 消耗掉非整数的输入  
	        }  
	        command = scanner.nextInt();  
	        scanner.nextLine(); // 消耗掉换行符（如果有的话），避免影响下一次输入  
	        if(command == 3) {
	        	break;
	        }
	        switch (command) {  
	            case 1:  
	                ErrorTraining.zeroLize(errorRecords);
	                Training(errorRecords);  
	                break;  
	  
	            case 2:  
	                errorTraining(errorRecords);  
	                break;  
	  
	            // 可以添加default来处理非1和2的输入  
	            default:  
	                System.out.println("无效的选择，请重新输入。");  
	                break;  
	        }  
	  
	        // 不在这里关闭scanner，因为它需要在整个循环中都被使用  
	    }  
	    // 在main方法结束前关闭scanner  
	    scanner.close();  
	}

	
	public static void Training(ErrorRecords errorRecords) {
		System.out.println("请选择年级（1~3）：");
		int selection;
		Scanner scanner = new Scanner(System.in);
		do {
			while (!scanner.hasNextInt()) {  
	            System.out.println("输入无效，请重新输入一个整数: ");  
	            scanner.next();
	        } 
			selection = scanner.nextInt();
		} while(selection != 1 && selection != 2 && selection != 3);
		switch(selection) {
		case 1:
			Grade_One.grade_One(errorRecords);
			break;
		case 2:
			Grade_Two.grade_Two(errorRecords);
			break;
		case 3:
			Grade_Three.grade_Three(errorRecords);
			break;
		}
	}
	
	public static void errorTraining(ErrorRecords errorRecords) {
		for(int i = 0; i < 20; i++) {
			ErrorTraining.accessErrorRecorder(errorRecords, i);
		}
		System.out.println("当前没有错题！");
	}

}
